<?php
$namaFile = "Impor_Prosedur_Gagal_".date("dmY").".xls";

// Function penanda awal file (Begin Of File) Excel
function xlsBOF() {
	echo pack("ssssss", 0x809, 0x8, 0x0, 0x10, 0x0, 0x0);
	return;
}

// Function penanda akhir file (End Of File) Excel
function xlsEOF() {
	echo pack("ss", 0x0A, 0x00);
	return;
}

// Function untuk menulis data (angka) ke cell excel
function xlsWriteNumber($Row, $Col, $Value) {
	echo pack("sssss", 0x203, 14, $Row, $Col, 0x0);
	echo pack("d", $Value);
	return;
}

// Function untuk menulis data (text) ke cell excel
function xlsWriteLabel($Row, $Col, $Value ) {
	$L = strlen($Value);
	echo pack("ssssss", 0x204, 8 + $L, $Row, $Col, 0x0, $L);
	echo $Value;
	return;
}

// header file excel
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Type: application/download");

// header untuk nama file
header("Content-Disposition: attachment; filename=".$namaFile."");
header("Content-Transfer-Encoding: binary ");

// memanggil function penanda awal file excel
xlsBOF();

// ------ membuat kolom pada excel --- //
xlsWriteLabel(0,0,"Sukses");               
xlsWriteLabel(0,1,"$sukses");              

xlsWriteLabel(1,0,"Gagal");               
xlsWriteLabel(1,1,"$gagal");              

xlsWriteLabel(3,0,"KODE");               
xlsWriteLabel(3,1,"NAMA PROSEDUR");              
xlsWriteLabel(3,2,"KETERANGAN");

// -------- menampilkan data --------- //

// koneksi ke mysql
require_once "../../config/koneksi.php";

// nilai awal untuk baris cell
$noBarisCell = 4;

// nilai awal untuk nomor urut data
$noData = 1;
$no = 1;
for($i=1;$i<=$gagal;$i++){
	xlsWriteLabel($noBarisCell,0,$data_gagal[$no]['kode']);
	xlsWriteLabel($noBarisCell,1,$data_gagal[$no]['nama']);
	xlsWriteLabel($noBarisCell,2,$data_gagal[$no]['keterangan']);
	$noBarisCell++;
	$noData++;
	$no++;
}

// memanggil function penanda akhir file excel
xlsEOF();
exit();
?>